// Vector  
// Changelog 02.02.07

#ifndef __Geometry__
#define __Geometry__
#include "math.h"
#include "vector.h"
#include <algorithm>
#include <iostream>

class Triangle{
protected:
  Vector p[3];
public:
  Triangle() {}
  Triangle(const Vector&,const Vector&,const Vector&);
  Triangle Shrink(const double&,const double&,const double&);
  double Area() const;
  inline Vector operator[](int i) const { return p[i]; }
};

//! \brief Compute the area of a triangle
inline double Triangle::Area() const
{
  return Norm((p[1]-p[0])/(p[2]-p[0]))/2.0;
}

class Quadrangle
{
protected:
  Vector p[4];
public:
  Quadrangle() {}
  Quadrangle(const Vector&,const Vector&,const Vector&,const Vector&);
  Quadrangle Shrink(const double&,const double&,const double&,const double&);
  double Area() const;
  //void Largest(Vector& a, Vector& b, Vector& c, Vector& d) ;
  inline Vector operator[](int i) const { return p[i]; }
  bool Carre() const;

};

//! \brief Compute the area of a quadrangle
inline double Quadrangle::Area() const
{
  return Norm((p[1]-p[0])/(p[2]-p[0]))+Norm((p[2]-p[0])/(p[3]-p[0]));
}

//! \brief Compute the area of a quadrangle
inline bool Quadrangle::Carre() const
{
	Vector ab=p[1]-p[0];
	Vector ad=p[3]-p[0];
	int angle=ab[0]*ad[0]+ab[1]*ad[1];

	if(angle==0)
	{
		Vector bc=p[2]-p[1];
		Vector ba=p[0]-p[1];
		int angle2=bc[0]*ba[0]+bc[1]*ba[1];

		if(angle2==0)
		{
				Vector cb=p[1]-p[2];
				Vector cd=p[3]-p[2];
				int angle3=cb[0]*cd[0]+cb[1]*cd[1];

				if(angle3==0)
				{
							return false;
				}
				else
					return false;
		}
		else
			return false;
	}
	else
		return false;
 
}


 


#endif